/**
 *
 * Praktikum CG WP WS13/14 Gruppe: Andreas Rebri(andreas.rebri@haw-hamburg.de)
 * Joschka Schulz(joschka.schulz@haw-hamburg.de) Aufgabe : Aufgabenblatt 5
 * Verwendete Quellen: -
 */
package edu.cg1.exercises.introduction;

import javax.vecmath.Point3d;
import javax.vecmath.TexCoord3f;
import static edu.cg1.exercises.introduction.AppearanceHelper.putTextuteOnTriangle;
/**
 * Diese Klasse Representiert ein Texturiertes Hochhaus
 */
public class HochhausTextured {

    /**
     * Erstellt ein Texturiertes Rechteckiges Hochhaus
     *
     * @param mesh
     */
    public static void createBuilding(ITriangleMesh mesh) {
        mesh.clear();
        //Erstellen des Rechtecks
        Point3d p1 = new Point3d(0, 0, 0);
        Point3d p2 = new Point3d(2, 0, 0);
        Point3d p3 = new Point3d(0, 0, 2);
        Point3d p4 = new Point3d(2, 0, 2);

        Point3d p5 = new Point3d(0, 5, 0);
        Point3d p6 = new Point3d(2, 5, 0);
        Point3d p7 = new Point3d(0, 5, 2);
        Point3d p8 = new Point3d(2, 5, 2);

        //Texturkoordianaten mit X,Y und Z
        TexCoord3f skyscraperLU = new TexCoord3f(0f, 1f, 0);
        TexCoord3f skyscraperRU = new TexCoord3f(0.5f, 1f, 0);
        TexCoord3f skyscraperLO = new TexCoord3f(0f, 0f, 0);
        TexCoord3f skyscraperRO = new TexCoord3f(0.5f, 0f, 0);

        TexCoord3f roofLU = new TexCoord3f(0.5f, 0.5f, 0);
        TexCoord3f roofRU = new TexCoord3f(1f, 0.5f, 0);
        TexCoord3f roofLO = new TexCoord3f(0.5f, 0f, 0);
        TexCoord3f roofRO = new TexCoord3f(1f, 0f, 0);

        TexCoord3f floorLU = new TexCoord3f(0.5f, 1f, 0);
        TexCoord3f floorRU = new TexCoord3f(1f, 1f, 0);
        TexCoord3f floorLO = new TexCoord3f(0.5f, 0.5f, 0);
        TexCoord3f floorRO = new TexCoord3f(1f, 0.5f, 0);

        //Front
        putTextuteOnTriangle(mesh, new Point3d[]{p5, p2, p1}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRU, skyscraperLU});
        putTextuteOnTriangle(mesh, new Point3d[]{p5, p6, p2}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRO, skyscraperRU});

        //Links
        putTextuteOnTriangle(mesh, new Point3d[]{p1, p3, p7}, 
                new TexCoord3f[]{skyscraperRU, skyscraperLU, skyscraperLO});
        putTextuteOnTriangle(mesh, new Point3d[]{p1, p7, p5}, 
                new TexCoord3f[]{skyscraperRU, skyscraperLO, skyscraperRO});

        //Rechts
        putTextuteOnTriangle(mesh, new Point3d[]{p6, p4, p2}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRU, skyscraperLU});
        putTextuteOnTriangle(mesh, new Point3d[]{p6, p8, p4}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRO, skyscraperRU});

        //Hinten
        putTextuteOnTriangle(mesh, new Point3d[]{p8, p3, p4}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRU, skyscraperLU});
        putTextuteOnTriangle(mesh, new Point3d[]{p8, p7, p3}, 
                new TexCoord3f[]{skyscraperLO, skyscraperRO, skyscraperRU});

        //Oben
        putTextuteOnTriangle(mesh, new Point3d[]{p7, p6, p5}, 
                new TexCoord3f[]{roofLO, roofRU, roofLU});
        putTextuteOnTriangle(mesh, new Point3d[]{p7, p8, p6}, 
                new TexCoord3f[]{roofLO, roofRO, roofRU});

        //Unten
        putTextuteOnTriangle(mesh, new Point3d[]{p1, p2, p3}, 
                new TexCoord3f[]{floorLU, floorRU, floorLO});
        putTextuteOnTriangle(mesh, new Point3d[]{p2, p4, p3}, 
                new TexCoord3f[]{floorRU, floorRO, floorLO});

    }

}
